package com.zhong.gang.app.ui.examine.payment;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.luck.picture.lib.tools.ToastUtils;
import com.zhong.gang.app.R;
import com.zhong.gang.app.databinding.ActivityPayMentBinding;
import com.zhong.gang.app.ui.examine.adpter.ExamineProgressAdapter;
import com.zhong.gang.app.ui.examine.adpter.modle.ExamineProgressBean;
import com.zhong.gang.app.ui.examine.adpter.modle.PriceBean;
import com.zhong.gang.app.ui.examine.presenter.ExaminePresenter;
import com.zhong.gang.applib.base.act.ActBaseRefresh;
import com.zhong.gang.applib.http.BaseDataBean;
import com.zhong.gang.applib.http.callback.DataCallBack;

import java.util.List;

public class PayMentAct extends ActBaseRefresh<ActivityPayMentBinding, ExamineProgressAdapter> {
    private ExaminePresenter presenter;
    private static final String ID = "ID";
    public static final void openAct(Context context, int id){
        Intent intent = new Intent(context, PayMentAct.class);
        intent.putExtra(ID,id);
        context.startActivity(intent);
    }
    @Override
    public int LayoutRes() {
        return R.layout.activity_pay_ment;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "付款审核";
    }

    @Override
    public void initView() {
        bind.setAct(this);
        bind.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        initrefrsh(bind.pullto,new ExamineProgressAdapter(),bind.recyclerView);
        presenter = new ExaminePresenter();
        getData();
    }

    @Override
    public void getData() {
        super.getData();
        int id = getIntent().getIntExtra(ID,0);
        presenter.getDetail(this,id,new DataCallBack<BaseDataBean<PriceBean>>(this){
            @Override
            public void onResponse(BaseDataBean<PriceBean> data) throws Exception {
                super.onResponse(data);
                bind.moneny.setText("："+data.getResult().getAmount()+"元");
                bind.sn.setText("："+data.getResult().getSn());
                bind.ySn.setText("："+data.getResult().getSn());
                bind.okButton.setVisibility(data.getResult().getStatus() == 0?View.VISIBLE:View.GONE);
                bind.notOkButton.setVisibility(data.getResult().getStatus() == 0?View.VISIBLE:View.GONE);
            }
        });
        presenter.recordList(this,id,new ActCallBack<BaseDataBean<List<ExamineProgressBean>>>(){
            @Override
            public void onResponse(BaseDataBean<List<ExamineProgressBean>> data) throws Exception {
                super.onResponse(data);
                setData(data.getResult());
            }
        });
    }

    public void onViewClicked(View view){
        switch (view.getId()){
            case R.id.ok_button:
                presenter.auditExamine(this,getIntent().getIntExtra(ID,0),2);
                 break;
            case R.id.not_ok_button:
                presenter.auditExamine(this,getIntent().getIntExtra(ID,0),1);
                break;
            case R.id.look_detail:
                ToastUtils.s(this,"原订单号和查看详情没等后台流程走完");
                break;
        }
    }
}
